package com.dianrui.agent.activity;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.androidkun.xtablayout.XTabLayout;
import com.dianrui.agent.R;
import com.dianrui.agent.adapter.StationPageAdapter;
import com.dianrui.agent.event.RankFragmentEvent;
import com.dianrui.agent.fragment.StationListFragment;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 站点排行
 */
public class StationRankActivity extends BaseActivity {

    private List<Fragment> fragments = new ArrayList<>();

    @BindView(R.id.top_right_img)
    ImageView topRightImg;
    @BindView(R.id.xTablayout)
    XTabLayout xTabLayout;
    @BindView(R.id.viewPager)
    ViewPager viewPager;

    @BindView(R.id.title)
    TextView title;


    @Override
    public int getContentViewId() {
        return R.layout.activity_station;
    }

    @Override
    public void initView() {
        title.setText("站点排行");
        List<String> titles = new ArrayList<>();
        titles.add("热门站点");
        titles.add("冷门站点");
        for (int i = 0; i < titles.size(); i++) {
            fragments.add(new StationListFragment());
        }
        StationPageAdapter adatper = new StationPageAdapter(getSupportFragmentManager(), fragments, titles);
        viewPager.setAdapter(adatper);
        viewPager.setOffscreenPageLimit(4);
        //将TabLayout和ViewPager关联起来。
        xTabLayout.setupWithViewPager(viewPager);
        //给TabLayout设置适配器
        xTabLayout.setupWithViewPager(viewPager);
        viewPager.setCurrentItem(0);
        xTabLayout.addOnTabSelectedListener(new XTabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(XTabLayout.Tab tab) {
                EventBus.getDefault().post(new RankFragmentEvent(tab.getPosition()+1));


            }

            @Override
            public void onTabUnselected(XTabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(XTabLayout.Tab tab) {

            }
        });

    }




    @OnClick({R.id.back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;

                default:
                    break;
        }
    }
}
